<template>
    <div>
        <table border="1">
            <tbody>
                <tr>
                    <th>房间号</th>
                    <th>
                        <input type="text" v-model="data.Num">
                    </th> 
                </tr>
                <tr>
                    <th>房间名称</th>
                    <th>
                        <input type="text" v-model="data.Name">
                    </th>
                </tr>
                <tr>
                    <th>描述</th>
                    <th>
                        <input type="text" v-model="data.Des">
                    </th>
                </tr>
                <tr>
                    <th>状态</th>
                    <th>
                            <input type="checkbox" v-model="data.State">选中启用否则禁用
                    </th>
                </tr>
                <tr>
                    <th>床位</th>
                    <th>
                        <input type="text" v-model="data.Bed">
                    </th>
                </tr>
                <tr>
                    <th>
                        <input type="button" value="修改" @click="Update">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { validateLocaleAndSetLanguage } from 'typescript';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
const data=ref({
    "Id": 0,
  "Num": "",
  "Name": "",
  "Des": "",
  "State": true,
  "Bed": "",
  "Delete": true
})

onMounted(()=>{
    Detail();
})

const router=useRoute();

const Detail=()=>{
    var val=router.query.Id;
    axios.get("https://localhost:7198/api/Home/Detail",{params:{Id:val}}).then(res=>{
        data.value=res.data;
    })


}

const ru=useRouter();

const Update=()=>{
    if(confirm('确定修改吗？')){
        axios.put("https://localhost:7198/api/Home/UpdateHome",data.value).then(res=>{
        if(res.data>0){
            alert('修改成功')
            ru.push({path:"/ShowView"})
        }
        else{
            alert('修改失败')
        }
    })
    }
   
}


</script>

